<template>
  <div class="password-page">
  <div class="password-change-container">
    <div class="card">
      <!-- 添加提示文字 -->
      <div class="info-text">在此页面修改您的密码</div>
      <el-form :model="data.user" label-width="120px" class="form">
        <el-form-item label="原密码">
          <el-input v-model="data.user.password" show-password placeholder="请输入原密码" />
        </el-form-item>

        <el-form-item label="新密码">
          <el-input v-model="data.user.newPassword" show-password placeholder="请输入新密码" />
        </el-form-item>

        <el-form-item label="确认新密码">
          <el-input v-model="data.user.confirmPasword" show-password placeholder="请再次输入新密码" />
        </el-form-item>

        <div class="button-container">
          <el-button type="primary" @click="save">保存</el-button>
        </div>
      </el-form>
    </div>
  </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import request from '@/utils/request'
import { ElMessage } from 'element-plus'
import router from '@/router'

const data = reactive({
  user: JSON.parse(localStorage.getItem('system-user') || '{}')
})

const save = () => {
  if (data.user.newPassword !== data.user.confirmPasword) {
    ElMessage.error('输入的两次新密码不一致')
    return
  }
  request.put('/updatePassword', data.user).then((res) => {
    if (res.code === '200') {
      ElMessage.success('修改密码成功，请重新登陆')
      localStorage.setItem('system-user', JSON.stringify(data.user))
      router.push('/login')
    } else {
      ElMessage.error(res.msg)
    }
  })
}
const clear = () => {
  data.user.password = ''
  data.user.newPassword = ''
  data.user.confirmPasword = ''
}
clear()
</script>

<style>
.password-page {
  min-height: 100vh;
  padding: 40px 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.password-page .password-change-container {
  width: 100%;
  max-width: 600px; /* 减小最大宽度 */
}

.password-page .card {
  width: 100%;
  background: white;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  position: relative;
}

/* 减小头部padding */
.password-page .info-text {
  padding: 40px 30px; /* 减小padding */
  background: linear-gradient(135deg, #409EFF 0%, #64B5F6 100%);
  text-align: center;
  color: white;
  font-size: 28px; /* 减小字体大小 */
  font-weight: 600;
  margin: 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* 减小表单区域padding */
.password-page .form {
  padding: 30px;
}

.password-page .el-form-item__label {
  font-size: 16px !important;
  font-weight: 500;
  color: #2c3e50;
}

.password-page .el-input__inner {
  font-size: 16px !important; /* 调整输入框内容字体大小 */
  height: 45px;  /* 适当调整输入框高度 */
}

.password-page .el-form-item {
  margin-bottom: 20px;
}

.password-page .el-input__wrapper {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04) !important;
  border-radius: 12px;
  height: 45px;
}

.password-page .el-input__wrapper:hover,
.password-page .el-input__wrapper.is-focus {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08) !important;
}

.password-page .button-container {
  padding: 0 30px 30px; /* 减小padding */
  text-align: center;
}

.password-page .button-container .el-button--primary {
  height: 45px; /* 减小按钮高度 */
  padding: 0 35px;
  font-size: 16px;
  font-weight: 500;
  border-radius: 12px;
  background: linear-gradient(135deg, #409EFF 0%, #64B5F6 100%);
  border: none;
  box-shadow: 0 4px 15px rgba(64, 158, 255, 0.2);
  transition: all 0.3s ease;
}

.password-page .button-container .el-button--primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(64, 158, 255, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .password-page .card {
    border-radius: 16px;
  }

  .password-page .info-text {
    padding: 30px 20px;
    font-size: 24px;
  }

  .password-page .form {
    padding: 20px;
  }

  .password-page .button-container {
    padding: 0 20px 20px;
  }
}
</style>


